<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="button" value="显示班级信息" onclick="showClass()">
    <table border="1" cellspacing="0" width="700">
        <thead>
            <tr>
                <th>班级编号</th>
                <th>班级名称</th>
            </tr>
        </thead>
        <tbody></tbody>
    </table>
    <script>
        function showClass(){
            let xhr=new XMLHttpRequest();
            xhr.open("get",'/class');
            xhr.onload=function(){
                // console.log(xhr.responseText);//string
               let arrs= JSON.parse(xhr.responseText);//数组
               let tb=document.querySelector("tbody");
               let str="";
               for(var i=0;i<arrs.length;i++){
                  str+="<tr><td>"+arrs[i].id+"</td><td>"+arrs[i].name+"</td></tr>";
  
               }
               tb.innerHTML=str;
               
            };
            xhr.send();
        }
    </script>
</body>
</html>